package org.code.mallspringboot.controller;

import org.code.mallspringboot.pojo.PmsPortalProductDetail;
import org.code.mallspringboot.service.*;
import org.code.mallspringboot.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private PmsProductService pmsProductService;

    @Autowired
    private PmsBrandService pmsBrandService;

    @Autowired
    private PmsProductAttributeService pmsProductAttributeService;

    @Autowired
    private PmsProductAttributeValueService pmsProductAttributeValueService;

    @Autowired
    private PmsProductFullReductionService pmsProductFullReductionService;

    @Autowired
    private PmsSkuStockService pmsSkuStockService;

    @GetMapping("/detail/{id}")
    public CommonResult fetchProductDetail(@PathVariable int id){
        PmsPortalProductDetail pmsPortalProductDetail = new PmsPortalProductDetail();
        pmsPortalProductDetail.setProduct(pmsProductService.selectById(id));
        pmsPortalProductDetail.setBrand(pmsBrandService.selectById(id));
        pmsPortalProductDetail.setProductAttributeList(pmsProductAttributeService.selectById(id));
        pmsPortalProductDetail.setProductAttributeValueList(pmsProductAttributeValueService.selectById(id));
        pmsPortalProductDetail.setProductFullReductionList(pmsProductFullReductionService.selectById(id));
        pmsPortalProductDetail.setSkuStockList(pmsSkuStockService.selectById(id));

        if (pmsPortalProductDetail != null){
            return CommonResult.success(pmsPortalProductDetail);
        }
        return CommonResult.failed("获取失败");
    }
}
